package com.lemon.service.impl;

import com.lemon.domain.StocktakingInfo;
import com.lemon.service.StocktakingInfoService;
import com.lemon.utils.UserThreadLocal;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lemon.domain.StocktakingLoss;
import com.lemon.mapper.StocktakingLossMapper;
import com.lemon.service.StocktakingLossService;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class StocktakingLossServiceImpl extends ServiceImpl<StocktakingLossMapper, StocktakingLoss> implements StocktakingLossService{

    private final StocktakingInfoService stocktakingInfoService;

    @Override
    @Transactional
    public void add(StocktakingLoss stocktakingLoss) {
        stocktakingLoss.setEmpId(UserThreadLocal.get().getId());
        stocktakingLoss.setCreateTime(LocalDateTime.now());
        baseMapper.insert(stocktakingLoss);
        StocktakingInfo byId = stocktakingInfoService.getById(stocktakingLoss.getStocktakingInfo());
        byId.setStatus(3);
        stocktakingInfoService.updateById(byId);
    }
}
